import pinia from '@/store'
import { useUserInfoStore } from '@/store/modules/user'
import router from '@/router/index'
import utils from '@/utils'

const userInfoStore = useUserInfoStore(pinia)

router.beforeEach((to, from, next) => {
	const login = to.matched.some((item) => item.meta.isLogin)
	const token = utils.getCache('userInfo').token
	if (login) {
		if (token) {
			next()
		} else {
			next('/login')
		}
	} else {
		next()
	}
})
